package com.feishi.core.socket.netty.handler;

import com.feishi.core.socket.common.SocketHandler;
import com.feishi.core.socket.common.lifecycle.SocketSession;
import com.feishi.core.util.common.EncryptUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

/**
 * @version 1.0
 * @auth caixq
 * @time 18-3-28 15:55
 **/
public class SocketNettyHandler extends SocketHandler {

    @Override
    protected void writeAndFlush(byte[] bytes) {
        if(ctx!=null){
            ByteBuf data=ctx.alloc().buffer(bytes.length);
            data.writeBytes(bytes);
            ctx.writeAndFlush(data);
        }else{
           this.connected=false;
           write(bytes);
        }

    }
    protected ChannelHandlerContext ctx;

    public ChannelHandlerContext getCtx() {
        return ctx;
    }

    public void setCtx(ChannelHandlerContext ctx) {
        this.ctx = ctx;
    }






}
